const http = require('http')
const fs = require('fs') // file system

http.createServer((req, res) => {
    if (req.url.includes('/api/getDetail')) {
        /*res.setHeader('Access-Control-Allow-Origin', '*')
        res.setHeader('Access-Control-Allow-Methods', '*')*/
        res.writeHead(200, {
            // 'Set-Cookie': 'myCookie=zms',
            'Content-Type': 'text/plain'
        });
        res.write('请求成功1')
        res.end()
    }

    if (req.url === '/index.html') {
        fs.readFile('index.html', (err, data) => {
            res.writeHead(200, {
                'Content-type': 'text/html'
            })
            res.write(data.toString())
            res.end()
        })
    }
}).listen(8000, () => {
    console.log('启动成功')
})
